package cn.ren.cloud.controller;

import cn.ren.cloud.dto.SmsSendDTO;
import cn.ren.cloud.result.JsonResult;
import cn.ren.cloud.service.IVerifyCodeService;
import org.springframework.web.bind.annotation.*;

/**
 * @author 23508
 */
@RestController
@RequestMapping("/verIfyCode")
public class VerifyCodeController {

    private final IVerifyCodeService verifyCodeService;

    public VerifyCodeController(IVerifyCodeService verifCodeService) {
        this.verifyCodeService = verifCodeService;
    }


    /**
     * 获取图形验证码
     *
     * @param key
     * @return
     */
    @GetMapping("/imageCode/{imageCodeKey}")
    public JsonResult imageCode(@PathVariable("imageCodeKey") String key) {
        String base64Str = verifyCodeService.getImageCode(key);
        return JsonResult.success(base64Str);
    }

    /**
     * 获取图形验证码
     *
     * @param dto
     * @return
     */
    @PostMapping("/sendSmsCode")
    public JsonResult sendSmsCode(@RequestBody  SmsSendDTO dto) {
        verifyCodeService.sendSmsCode(dto);
        return JsonResult.success();
    }

}
